/** 
 * 从身份证号码中获取生日和性别
 * 规则：7-14位表示出生年、月、日，17位计数代表男性，偶数代表女性
 * 
*/
function getInfoFromIdCode2(idCode) {
    let res = {
        'year': 0,
        'month': 0,
        'day': 0,
        'gender': ''
    };

    res['year'] = parseInt(idCode.substring(6, 10));
    res['month'] = parseInt(idCode.substring(10, 12));
    res['day'] = parseInt(idCode.substring(12, 14));

    res['gender'] = parseInt(idCode[16]) % 2 == 0 ? '女' : '男';

    return res;
}

function getInfoFromIdCode(idCode) {
    if (idCode.length != 18) {
        return "身份证号码错误";
    }

    let year = idCode.substring(6, 10);
    let month = idCode.substring(10, 12);
    let day = idCode.substring(12, 14);

    return year + '-' + month + '-' + day;
}

console.log(getInfoFromIdCode('120102199903080944'));


/**
 * 判断密码是否符合要求，要求包含大、小写字母和数字字符
 */
function isRight(passwd, minLen = 8) {
    passwd = passwd.trim();
    if (passwd.length < minLen) {
        return false;
    }

    let lowFlag = false;
    let upFlag = false;
    let numberFlag = false;
    for (let c of passwd) {
        if (c >= 'a' && c <= 'z') {
            lowFlag = true;
        }
        if (c >= 'A' && c <= 'Z') {
            upFlag = true;
        }
        if (c >= '0' && c <= '9') {
            numberFlag = true;
        }
    }

    return lowFlag && upFlag && numberFlag;
}

console.log(isRight('asdf1234S'))

/**
 * 输出字符串中字符的个数
 */
function charNumber(srcStr) {
    let dict = {};
    for (let i = 0; i < srcStr.length; i++) {
        if (!dict[srcStr[i]]) {
            dict[srcStr[i]] = 1;
        } else {
            dict[srcStr[i]] += 1;
        }
    }
    return dict;
}
console.log(charNumber('helloworld'))

/**
 * 求100～1000之间所有水仙花数
 * 153是水仙花数：1^3+5^3+3^3=153,各位数字三次方之和等于该数
 */
function findFlower() {
    let result = [];
    for (let n = 100; n < 1000; n++) {
        let a = parseInt(n / 100);
        let c = n % 10;
        let b = (n - 100 * a - c) / 10;

        if (Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3) == n) {
            result.push(n);
        }
    }

    return result;
}

console.log(findFlower());




